﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DCT.AutoUpdate.Code.Config;

namespace DCT.AutoUpdate.CodeTest.Config
{
    public class TagNameXmlConfigParsertest
    {
        public static string Xml = @"
<?xml version=""1.0"" encoding=""utf-8"" ?>
<root>
    <code>0</code>
    <version>2.0</version>
    <updatetime>20120102</updatetime>
    <whatsnew>
        <item>
            <![CDATA[ 
            修正xxxxbug
            ]]>
        </item>
        <item>
            <![CDATA[ 
            提高性能
            ]]>
        </item>
    </whatsnew>
    <downloads>
        <item>
            <url>http://localhost:3643/package/1.0/accessibilitycpl.dll</url>
        </item>
        <item>
            <url>http://localhost:3643/package/1.0/ACCTRES.dll</url>
        </item>
        <item>
            <url>http://localhost:3643/package/1.0/acledit.dll</url>
        </item>
        <item>
            <url>http://localhost:3643/package/1.0/aclui.dll</url>
        </item>
        <item>
            <url>http://localhost:3643/package/1.0/acppage.dll</url>
        </item>
        <item>
            <url>http://localhost:3643/package/1.0/acproxy.dll</url>
        </item>
    </downloads>
    <tasks>
        <task>
            <type>copy</type>
            <source>*</source>
            <target>#appfolder#</target>
        </task>
        <!--<task>
            <type>exec</type>
            <source></source>
        </task>-->
    </tasks>
</root>
";

        public void GetTest() {
            IConfigParser cp = new AutoUpdateXmlConfigParser();
            cp.Load(Xml);
            Console.WriteLine("======GetValue -- Test");
            Console.WriteLine("code=" + cp.GetVal("code", ""));             //out:0
            Console.WriteLine("version=" + cp.GetVal("version", ""));       //out:2.0
            Console.WriteLine("updatetime=" + cp.GetVal("updatetime", "")); //out:20120102

            Console.WriteLine("======GetListVal -- Test");
            Console.WriteLine("whatsnew = ");
            foreach (var item in cp.GetListVal("whatsnew"))
            {
                Console.WriteLine("\t" + item);
            }

            Console.WriteLine("======GetListKV -- Test");
            Console.WriteLine("downloads = ");
            foreach (var item in cp.GetListKV("downloads"))
            {
                foreach (var kv in item)
                {
                    Console.WriteLine("k=" + kv.Key + "|v=" + kv.Value);
                }
            }
        }
    }
}
